package org.rooster.genetic.monitor;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 7/14/12
 * Time: 10:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class TimeMonitor extends Thread{

    private boolean MAX_TIME_REACHED = false;
    private int GIVEN_TIME_LIMIT;

    /**
     *
     * @param time the time to run GA in seconds
     */
    public TimeMonitor(int time) {
        this.GIVEN_TIME_LIMIT = time;
    }

    @Override
    public void run() {

        while (true) {
            try {
                sleep(GIVEN_TIME_LIMIT * 1000);
                MAX_TIME_REACHED = true;
                System.out.println("Progress Monitor : MAXIMUM TIME REACHED " + GIVEN_TIME_LIMIT + " seconds");
                stop();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public boolean isMAX_TIME_REACHED() {
        return MAX_TIME_REACHED;
    }
}
